#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>

#define FIFO_PATH "myfifo"


int main()
{

 if(mkfifo(FIFO_PATH, 0666) < 0 && errno != EEXIST)
 {
 
   perror("create fifo failed");

   return -1;
 
 }
 else
 {
 
  int fd = open(FIFO_PATH, O_CREAT|O_WRONLY, 0666);

  if(fd > 0)
  {
  
   int num = 0;

   while(1)
   {
     
     char content[128];

     sprintf(content, "this is fifo stream -----> %d\n\0", num);

     write(fd, content, strlen(content));

     puts("write fifo stream ");

     printf("write fifo stream %d\n", num);

     num++;

   }

  }
  else
  {
  
    perror("open fifo file failed");

  }
  

 }


return 0;
}




